

package javaapplication1;


import java.util.HashMap;

public class RobotFactory {

 private interface RobotFac{
  public Robot create(Robot rbt);
 }

 private class RV1Fac implements RobotFac{
  public Robot create(Robot rbt){ return new RV1();}
 }

 private class RV2Fac implements RobotFac{
  public Robot create(Robot rbt){ return new RV2();}
 }

 private class AiboFac implements RobotFac{
  public Robot create(Robot rbt){ return new Aibo();}
 }

 private class ArmAdditionFac implements RobotFac{
  public Robot create(Robot rbt){ return new ArmAddition(rbt);}
 }

 private class SmartAdditionFac implements RobotFac{
  public Robot create(Robot rbt){ return new SmartRobot(rbt);}
 }
 private class allFac implements RobotFac{
  public Robot create(Robot rbt){ return new SmartRobot(rbt);}
 }



  private HashMap<String,RobotFac> robotFactory;

public RobotFactory(){
  robotFactory=new HashMap<String,RobotFac> ();
  robotFactory.put("RV1", new RV1Fac());
  robotFactory.put("RV2", new RV2Fac());
  robotFactory.put("Aibo", new AiboFac());
  robotFactory.put("arm", new ArmAdditionFac());
  robotFactory.put("smartKit", new SmartAdditionFac());
  robotFactory.put("all", new allFac());
 }

 public Robot createRobot(String type, String type2 ){

     if (type2 == null)
     {
         if (((RobotFac)robotFactory.get(type))!=null)
            return ((RobotFac)robotFactory.get(type)).create(null);
     }

     if (type2 != null)
     {

         if ((((RobotFac)robotFactory.get(type2))!=null) && (!type2.equalsIgnoreCase("all")))
         {
             return ((RobotFac)robotFactory.get(type2)).create(((RobotFac)robotFactory.get(type)).create(null));
         }
         if ((((RobotFac)robotFactory.get(type2))!=null) && (type2.equalsIgnoreCase("all")))
         {
             return (((RobotFac)robotFactory.get("arm")).create(((RobotFac)robotFactory.get("smartKit")).create(((RobotFac)robotFactory.get(type)).create(null))));
         }
         else return null;
     }
     else return null;
 }
 
  public Robot createRobot(String type, Boolean  arm, Boolean smart)
  {
      if (arm)
     {
          if (smart)
          {
              return (((RobotFac)robotFactory.get("arm"))
                      .create(((RobotFac)robotFactory.get("smartKit"))
                      .create(((RobotFac)robotFactory.get(type)).create(null))));
          }
          return ((RobotFac)robotFactory.get("arm"))
                  .create(((RobotFac)robotFactory.get(type)).create(null));

     }
      else if (smart)
      {
          return ((RobotFac)robotFactory.get("smartKit"))
                  .create(((RobotFac)robotFactory.get(type)).create(null));
          
      }
      else 
      {

         return ((RobotFac)robotFactory.get(type)).create(null);
      }


  }
}
